#!/bin/bash
# Install Calica
ETCD_CA=`cat /etc/kubernetes/pki/etcd/ca.crt | base64 | tr -d '\n'`
ETCD_CERT=`cat /etc/kubernetes/pki/etcd/server.crt | base64 | tr -d '\n'`
ETCD_KEY=`cat /etc/kubernetes/pki/etcd/server.key | base64 | tr -d '\n'`
POD_SUBNET=`cat /etc/kubernetes/manifests/kube-controller-manager.yaml | grep cluster-cidr= | awk -F= '{print $NF}'`

cd $HOME
git clone https://gitee.com/zjy_1671/k8s-ha-install.git && \
cd $HOME/k8s-ha-install && \
git checkout manual-installation-v1.20.x && \
cd calico/ && \
sed -i 's#etcd_endpoints: "http://<ETCD_IP>:<ETCD_PORT>"#etcd_endpoints: "https://{{ master_ip }}:2379,https://{{ node01_ip }}:2379,https://{{ node02_ip }}:2379"#g' calico-etcd.yaml && \
sed -i "s/# etcd-key: null/etcd-key: ${ETCD_KEY}/g; s/# etcd-cert: null/etcd-cert: ${ETCD_CERT}/g; s/# etcd-ca: null/etcd-ca: ${ETCD_CA}/g" calico-etcd.yaml && \
sed -i 's#etcd_ca: ""#etcd_ca: "/calico-secrets/etcd-ca"#g; s#etcd_cert: ""#etcd_cert: "/calico-secrets/etcd-cert"#g; s#etcd_key: "" #etcd_key: "/calico-secrets/etcd-key" #g' calico-etcd.yaml && \
sed -i 's@# - name: CALICO_IPV4POOL_CIDR@- name: CALICO_IPV4POOL_CIDR@g; s@#   value: "192.168.0.0/16"@  value: '"${POD_SUBNET}"'@g' calico-etcd.yaml && \
kubectl apply -f calico-etcd.yaml


#Install Metrics
cd /root/k8s-ha-install/metrics-server-0.4.x-kubeadm/ && \
kubectl  create -f comp.yaml


#Install Dashboard
cd /root/k8s-ha-install/dashboard/ && \
kubectl  create -f .
